package com.yumeng.webapp.shiro.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.yumeng.common.auth.BaseAuthHelper;
import com.yumeng.framework.persistence.mybatis.config.MybatisPlusConfiguration;
import com.yumeng.framework.persistence.mybatis.plugins.dynamictable.TableNameDateSuffixType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author wxd
 * @date 2025/10/15 16:18
 */
@Slf4j
@Configuration
public class MybatisPlusConfig extends MybatisPlusConfiguration {


    @Override
    protected DbType mainDbType() {
        return DbType.MYSQL;
    }


    @Override
    protected Long getCurrTenantId() {
        Long tenantId = BaseAuthHelper.getCurrAuthInfo(false).getIdentityIdLongVal();
        log.info("当前租户id(tenantId):{}",tenantId);
        return tenantId;
    }



/*    @Override
    protected List<String> getTenantIgnoreTables() {
        return List.of("demo_test");
    }*/

    /**
     * 动态表名映射（日期模式）
     * 表名-> 日期类型
     *
     * @return
     */
    @Override
    protected Map<String, TableNameDateSuffixType> getDynamicTableNameMapForDateMode() {
        Map<String, TableNameDateSuffixType> map = new HashMap<>();
        map.put("demo_order", TableNameDateSuffixType.YEAR);
        map.put("demo_order_detail", TableNameDateSuffixType.YEAR);
        return map;
    }

    /**
     * 动态表名映射（idMod模式）
     * 表名-> 分几张表
     *
     * @return
     */
    @Override
    protected Map<String, Integer> getDynamicTableNameMapForIdModMode() {
        Map<String, Integer> map = new HashMap<>();
        map.put("demo_test", 3);
        return map;
    }

}
